package com.xsm.takephoto;

import java.io.File;
import java.util.ArrayList;

import com.xsm.activitygroup.R;

import android.R.integer;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.LinearLayout.LayoutParams;

public class TakePhotoDialog extends Dialog{
Activity context;
int REQUEST_CODE_PICK_IMAGE=4;
int REQUEST_CODE_CAPTURE_CAMEIA=5;
Dialog dialog;
	public TakePhotoDialog(Activity context) {
		super(context);
		this.context=context;
		dialog=this;
	}
	public TakePhotoDialog(Activity context,int theme) {
		super(context,theme);
		this.context=context;
		dialog=this;
	}
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);		
		
		ListView listView=new ListView(context);
		ArrayList<String> arrayList=new ArrayList<String>();
		arrayList.add("本地相册");
		arrayList.add("拍照");
		ArrayAdapter<String> adapter=new ArrayAdapter<String>(context, R.layout.listtext,arrayList);
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
			if(arg2==0){
				    Intent intent = new Intent(Intent.ACTION_PICK);  
			       intent.setType("image/*");//相片类型  
			       context.startActivityForResult(intent, REQUEST_CODE_PICK_IMAGE);  
			}else {
				  String state = Environment.getExternalStorageState();  
				 if (state.equals(Environment.MEDIA_MOUNTED)) {  
					 Intent getImageByCamera = new Intent("android.media.action.IMAGE_CAPTURE");  
				     context.startActivityForResult(getImageByCamera,REQUEST_CODE_CAPTURE_CAMEIA);      
					}else {  
				  Toast.makeText(context.getApplicationContext(), "请确认已经插入SD卡", Toast.LENGTH_LONG).show();  
				 }
			}
			dialog.dismiss();
			}
		});
	
		setContentView(listView);
	}
}




